<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-input v-model="query.value" clearable placeholder="输入搜索内容" style="width: 200px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <el-select v-model="query.type" clearable placeholder="类型" class="filter-item" style="width: 130px">
          <el-option v-for="item in queryTypeOptions" :key="item.key" :label="item.display_name" :value="item.key" />
        </el-select>
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="消费者ID">
            <el-input v-model="form.consumerId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商铺ID">
            <el-input v-model="form.shopId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="订单类型，同 shop 表 category 冗余处理">
            <el-input v-model="form.category" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="会员卡id">
            <el-input v-model="form.cardId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="订单金额">
            <el-input v-model="form.amount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="优惠金额">
            <el-input v-model="form.discountAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="实付金额">
            <el-input v-model="form.payAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="支付时间">
            <el-input v-model="form.payDate" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="支付状态，1：未支付，2已取消，3已过期，4已支付 5已撤销（后台退款）6 已退款（客户申请退款，团队） 9已支付">
            <el-input v-model="form.payStatus" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column v-if="columns.visible('id')" prop="id" label="id" />
        <el-table-column v-if="columns.visible('unique')" prop="unique" label="uuid唯一标识码" />
        <el-table-column v-if="columns.visible('consumerId')" prop="consumerId" label="消费者ID" />
        <el-table-column v-if="columns.visible('shopId')" prop="shopId" label="商铺ID" />
        <el-table-column v-if="columns.visible('category')" prop="category" label="订单类型，同 shop 表 category 冗余处理" />
        <el-table-column v-if="columns.visible('cardId')" prop="cardId" label="会员卡id" />
        <el-table-column v-if="columns.visible('amount')" prop="amount" label="订单金额" />
        <el-table-column v-if="columns.visible('discountAmount')" prop="discountAmount" label="优惠金额" />
        <el-table-column v-if="columns.visible('payAmount')" prop="payAmount" label="实付金额" />
        <el-table-column v-if="columns.visible('payDate')" prop="payDate" label="支付时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.payDate) }}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="columns.visible('payStatus')" prop="payStatus" label="支付状态，1：未支付，2已取消，3已过期，4已支付 5已撤销（后台退款）6 已退款（客户申请退款，团队） 9已支付" />
        <el-table-column v-permission="['admin','consumerOrder:edit','consumerOrder:del']" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudConsumerOrder from '@/api/consumerOrder'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import MaterialList from "@/components/material";

// crud交由presenter持有
const defaultCrud = CRUD({ title: '客户订单', url: 'api/consumerOrder', sort: 'id,desc', crudMethod: { ...crudConsumerOrder }})
const defaultForm = { id: null, unique: null, consumerId: null, shopId: null, category: null, cardId: null, amount: null, discountAmount: null, payAmount: null, payDate: null, payStatus: null, createDate: null }
export default {
  name: 'ConsumerOrder',
  components: { pagination, crudOperation, rrOperation, udOperation ,MaterialList},
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()],
  data() {
    return {
      
      permission: {
        add: ['admin', 'consumerOrder:add'],
        edit: ['admin', 'consumerOrder:edit'],
        del: ['admin', 'consumerOrder:del']
      },
      rules: {
        unique: [
          { required: true, message: 'uuid唯一标识码不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'id', display_name: 'id' },
        { key: 'unique', display_name: 'uuid唯一标识码' },
        { key: 'consumerId', display_name: '消费者ID' },
        { key: 'shopId', display_name: '商铺ID' },
        { key: 'category', display_name: '订单类型，同 shop 表 category 冗余处理' },
        { key: 'cardId', display_name: '会员卡id' },
        { key: 'amount', display_name: '订单金额' },
        { key: 'discountAmount', display_name: '优惠金额' },
        { key: 'payAmount', display_name: '实付金额' },
        { key: 'payDate', display_name: '支付时间' },
        { key: 'payStatus', display_name: '支付状态，1：未支付，2已取消，3已过期，4已支付 5已撤销（后台退款）6 已退款（客户申请退款，团队） 9已支付' }
      ]
    }
  },
  watch: {
  },
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      const query = this.query
      if (query.type && query.value) {
        this.crud.params[query.type] = query.value
      }else{
        delete this.crud.params.id
        delete this.crud.params.unique
        delete this.crud.params.consumerId
        delete this.crud.params.shopId
        delete this.crud.params.category
        delete this.crud.params.cardId
        delete this.crud.params.amount
        delete this.crud.params.discountAmount
        delete this.crud.params.payAmount
        delete this.crud.params.payDate
        delete this.crud.params.payStatus
      }
      return true
    }, // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
    },
  }
}



</script>

<style scoped>
  .table-img {
    display: inline-block;
    text-align: center;
    background: #ccc;
    color: #fff;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
    vertical-align: middle;
    width: 32px;
    height: 32px;
    line-height: 32px;
  }
</style>
